{% extends 'CpmJovenesBundle:Layout:admin_layout.html.twig' %}

{% block title %}Redactar Correo{% endblock %}

{% block content %}
	<div class="proyecto_right_box">
		{{ common.SelectVariablesDePlantillas("#cpm_jovenesbundle_correotype_cuerpo","proyectos") }}
	</div>

<form action="{{ path('correo_create') }}" method="post" {{ form_enctype(form) }}>
    {{ form_widget(form) }}
    <a href="#" class="jslink" onclick="addDynamicForm('#cpm_jovenesbundle_correotype_archivos'); return false;">
            Agregar archivo
    </a>
    <p>
        <button type="submit">Enviar</button>
    </p>
</form>

<script>

	$(function(){
		$('#cpm_jovenesbundle_correotype_destinatario').change(function (){
			var label = this.options[this.selectedIndex].label;
			var i = label.substring(label.lastIndexOf("<") + 1, label.lastIndexOf(">"));
			$('#cpm_jovenesbundle_correotype_email').val(i);
		});
		
		    
		$('#cpm_jovenesbundle_correotype_destinatario_text').blur(function() {
			console.log(this.value);
			var label = this.value;
			var i = label.substring(label.lastIndexOf("<") + 1, label.lastIndexOf(">"));
			this.value = label.substring(0,label.lastIndexOf("<"));
			
			$('#cpm_jovenesbundle_correotype_email').val(i);
		}).keypress(function(event){
				 var code = (event.keyCode ? event.keyCode : event.which);
				 if(code == 13) { //Enter
				   $(this).blur();
				 }
		});
	});
</script>
<ul class="record_actions">
    <li>
        <a href="{{ path('correo') }}">
            Volver al listado
        </a>
    </li>
</ul>
{% endblock %}